package com.weiyin.examination.adapter;

import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiyin.examination.R;
import com.weiyin.examination.module.SelectionModule;
import com.weiyin.examination.util.LayoutHelper;

import java.util.List;

/**
 * @author njf
 * @date 2017/9/21
 */

public class CourseA7Adapter extends BaseQuickAdapter<SelectionModule, BaseViewHolder> {
    private Activity activity;

    public CourseA7Adapter(Activity activity, @LayoutRes int layoutResId, @Nullable List<SelectionModule> data) {
        super(layoutResId, data);
        this.activity = activity;
    }

    @Override
    protected BaseViewHolder createBaseViewHolder(View view) {
        LayoutHelper layoutHelper = new LayoutHelper(activity);
        layoutHelper.scaleView(view);
        return super.createBaseViewHolder(view);
    }

    private OnItemClickInterface onItemClickInterface;

    public void setOnItemClickInterface(OnItemClickInterface onItemClickInterface) {
        this.onItemClickInterface = onItemClickInterface;
    }

    public interface OnItemClickInterface {
        void onItemClick(BaseViewHolder helper, int position);
    }

    @Override
    protected void convert(final BaseViewHolder helper, SelectionModule item) {
        if (item != null) {
            helper.setText(R.id.courseA7ItemTextContent, item.getSubjectContent());
            helper.getView(R.id.courseA7ItemLayout).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickInterface != null) {
                        onItemClickInterface.onItemClick(helper, helper.getAdapterPosition());
                    }
                }
            });
        }
    }
}
